// TestCore.cpp
//
#include "stdafx.h"
#include <gtest\gtest.h>
#include "IniReader.h"
#include <Windows.h>
#include <string>
#include <WinUser.h>

struct display
{
	int x,y;
	int width,heigh;
};

void test()
{
display display1,display2;
display1.x = 3;
display1.y = 0;
display1.heigh = 768;
display1.width = 1024;
display2 = display1;
display2.x = 17;
int n = 3;
display   *p = new   display[n];
delete [] p;
display displayList[20];
}

std::string GetDataDir(char* file_name)
{
	char app_path[MAX_PATH] = {0};
	::GetModuleFileName(NULL ,app_path, MAX_PATH);
	(strrchr(app_path, '\\'))[1] = 0;

	//printf("%s", app_path);
	return std::string(app_path)+file_name;
}

bool IsPrime(int n)
{
    // Trivial case 1: small numbers
    if (n <= 1) return false;

    // Trivial case 2: even numbers
    if (n % 2 == 0) return n == 2;

    // Now, we have that n is odd and n >= 3.

    // Try to divide n by every odd number i, starting from 3
    for (int i = 3; ; i += 2) {
        // We only have to try i up to the squre root of n
        if (i > n/i) break;

        // Now, we have i <= n/i < n.
        // If n is divisible by i, n is not prime.
        if (n % i == 0) return false;
    }
    // n has no integer factor in the range (1, n), and thus is prime.
    return true;
}

class IsPrimeParamTest : public::testing::TestWithParam<int>
{
};

TEST_P(IsPrimeParamTest, HandleTrueReturn)
{
    int n =  GetParam();
    EXPECT_TRUE(IsPrime(n));
}

int prime[6] = {3,5,11,17,23};

INSTANTIATE_TEST_CASE_P(TrueReturn, IsPrimeParamTest, testing::ValuesIn(prime));

TEST(TestCore, ReadIni)
{
	CIniReader ini(GetDataDir("testres\\TestCase.ini").c_str());
	int caseCount = ini.ReadInteger("TestCore","case_count",0);
	test();
}